home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / quake2.zip / QJOE19.ZIP / WEAPONS.QC < prev    next >
Text File  |  1996-08-20  |  28KB  |  1,310 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav"); // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");  // super spikes
  21.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  25.  
  26.     precache_sound ("demon/dhit2.wav"); //Flesh Tearing -QJOE-
  27.     precache_sound ("dog/idle.wav"); //Biting sound -QJOE-
  28. };
  29.  
  30. float() crandom =
  31. {
  32.     return 2*(random() - 0.5);
  33. };
  34.  
  35. /*
  36. ================
  37. W_FireAxe
  38. ================
  39. */
  40. void() W_FireAxe =
  41. {
  42.     local   vector  source;
  43.     local   vector  org;
  44.  
  45.     source = self.origin + '0 0 16';
  46.     traceline (source, source + v_forward*64, FALSE, self);
  47.     if (trace_fraction == 1.0)
  48.         return;
  49.     
  50.     org = trace_endpos - v_forward*4;
  51.  
  52.     if (trace_ent.takedamage)
  53.     {
  54.         trace_ent.axhitme = 1;
  55.         SpawnBlood (org, '0 0 0', 20);
  56.         T_Damage (trace_ent, self, self, 20);
  57.     }
  58.     else
  59.     {       // hit wall
  60.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  61.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  62.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  63.         WriteCoord (MSG_BROADCAST, org_x);
  64.         WriteCoord (MSG_BROADCAST, org_y);
  65.         WriteCoord (MSG_BROADCAST, org_z);
  66.     }
  67. };
  68.  
  69. //====QJOE====
  70. void() W_Bite =
  71. {
  72.     local   vector  source;
  73.     local   vector  org;
  74.  
  75.     source = self.origin + '0 0 16';
  76.     traceline (source, source + v_forward*64, FALSE, self);
  77.     if (trace_fraction == 1.0)
  78.         return;
  79.     
  80.     org = trace_endpos - v_forward*4;
  81.  
  82.     if (trace_ent.takedamage)
  83.     {
  84.         trace_ent.axhitme = 1;
  85.         sound (self, CHAN_WEAPON, "demon/dhit2.wav", 1, ATTN_NORM);
  86.         SpawnBlood (org, '0 0 0', 100);
  87.         T_Damage (trace_ent, self, self, 5);
  88.     }
  89.     else
  90.     {       // hit wall
  91.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  92.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  93.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  94.         WriteCoord (MSG_BROADCAST, org_x);
  95.         WriteCoord (MSG_BROADCAST, org_y);
  96.         WriteCoord (MSG_BROADCAST, org_z);
  97.     }
  98. };
  99. //===QJOE.end===
  100.  
  101.  
  102.  
  103. //============================================================================
  104.  
  105.  
  106. vector() wall_velocity =
  107. {
  108.     local vector    vel;
  109.     
  110.     vel = normalize (self.velocity);
  111.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  112.     vel = vel + 2*trace_plane_normal;
  113.     vel = vel * 200;
  114.     
  115.     return vel;
  116. };
  117.  
  118.  
  119. /*
  120. ================
  121. SpawnMeatSpray
  122. ================
  123. */
  124. void(vector org, vector vel) SpawnMeatSpray =
  125. {
  126.     local   entity missile, mpuff;
  127.     local   vector  org;
  128.  
  129.     missile = spawn ();
  130.     missile.owner = self;
  131.     missile.movetype = MOVETYPE_BOUNCE;
  132.     missile.solid = SOLID_NOT;
  133.  
  134.     makevectors (self.angles);
  135.  
  136.     missile.velocity = vel;
  137.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  138.  
  139.     missile.avelocity = '3000 1000 2000';
  140.     
  141. // set missile duration
  142.     missile.nextthink = time + 1;
  143.     missile.think = SUB_Remove;
  144.  
  145.     setmodel (missile, "progs/zom_gib.mdl");
  146.     setsize (missile, '0 0 0', '0 0 0');            
  147.     setorigin (missile, org);
  148. };
  149.  
  150. /*
  151. ================
  152. SpawnBlood
  153. ================
  154. */
  155. void(vector org, vector vel, float damage) SpawnBlood =
  156. {
  157.     particle (org, vel*0.1, 73, damage*2);
  158. };
  159.  
  160. /*
  161. ================
  162. spawn_touchblood
  163. ================
  164. */
  165. void(float damage) spawn_touchblood =
  166. {
  167.     local vector    vel;
  168.  
  169.     vel = wall_velocity () * 0.2;
  170.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  171. };
  172.  
  173.  
  174. /*
  175. ================
  176. SpawnChunk
  177. ================
  178. */
  179. void(vector org, vector vel) SpawnChunk =
  180. {
  181.     particle (org, vel*0.02, 0, 10);
  182. };
  183.  
  184. /*
  185. ==============================================================================
  186.  
  187. MULTI-DAMAGE
  188.  
  189. Collects multiple small damages into a single damage
  190.  
  191. ==============================================================================
  192. */
  193.  
  194. entity  multi_ent;
  195. float   multi_damage;
  196.  
  197. void() ClearMultiDamage =
  198. {
  199.     multi_ent = world;
  200.     multi_damage = 0;
  201. };
  202.  
  203. void() ApplyMultiDamage =
  204. {
  205.     if (!multi_ent)
  206.         return;
  207.     T_Damage (multi_ent, self, self, multi_damage);
  208. };
  209.  
  210. void(entity hit, float damage) AddMultiDamage =
  211. {
  212.     if (!hit)
  213.         return;
  214.     
  215.     if (hit != multi_ent)
  216.     {
  217.         ApplyMultiDamage ();
  218.         multi_damage = damage;
  219.         multi_ent = hit;
  220.     }
  221.     else
  222.         multi_damage = multi_damage + damage;
  223. };
  224.  
  225. /*
  226. ==============================================================================
  227.  
  228. BULLETS
  229.  
  230. ==============================================================================
  231. */
  232.  
  233. /*
  234. ================
  235. TraceAttack
  236. ================
  237. */
  238. void(float damage, vector dir) TraceAttack =
  239. {
  240.     local   vector  vel, org;
  241.     
  242.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  243.     vel = vel + 2*trace_plane_normal;
  244.     vel = vel * 200;
  245.  
  246.     org = trace_endpos - dir*4;
  247.  
  248.     if (trace_ent.takedamage)
  249.     {
  250.         SpawnBlood (org, vel*0.2, damage);
  251.         AddMultiDamage (trace_ent, damage);
  252.     }
  253.     else
  254.     {
  255.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  256.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  257.         WriteCoord (MSG_BROADCAST, org_x);
  258.         WriteCoord (MSG_BROADCAST, org_y);
  259.         WriteCoord (MSG_BROADCAST, org_z);
  260.     }
  261. };
  262.  
  263. /*
  264. ================
  265. FireBullets
  266.  
  267. Used by shotgun, super shotgun, and enemy soldier firing
  268. Go to the trouble of combining multiple pellets into a single damage call.
  269. ================
  270. */
  271. void(float shotcount, vector dir, vector spread) FireBullets =
  272. {
  273.     local   vector direction;
  274.     local   vector  src;
  275.     
  276.     makevectors(self.v_angle);
  277.  
  278.     src = self.origin + v_forward*10;
  279.     src_z = self.absmin_z + self.size_z * 0.7;
  280.  
  281.     ClearMultiDamage ();
  282.     while (shotcount > 0)
  283.     {
  284.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  285.  
  286.         traceline (src, src + direction*2048, FALSE, self);
  287.         if (trace_fraction != 1.0)
  288.             TraceAttack (4, direction);
  289.  
  290.         shotcount = shotcount - 1;
  291.     }
  292.     ApplyMultiDamage ();
  293. };
  294.  
  295. /*
  296. ================
  297. W_FireShotgun
  298. ================
  299. */
  300. void() W_FireShotgun =
  301. {
  302.     local vector dir;
  303.  
  304.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  305.  
  306.     self.punchangle_x = -2;
  307.     
  308.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  309.     dir = aim (self, 100000);
  310.     FireBullets (6, dir, '0.04 0.04 0');
  311. };
  312.  
  313.  
  314. /*
  315. ================
  316. W_FireSuperShotgun
  317. ================
  318. */
  319. void() W_FireSuperShotgun =
  320. {
  321.     local vector dir;
  322.  
  323.     if (self.currentammo == 1)
  324.     {
  325.         W_FireShotgun ();
  326.         return;
  327.     }
  328.         
  329.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  330.  
  331.     self.punchangle_x = -4;
  332.     
  333.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  334.     dir = aim (self, 100000);
  335.     FireBullets (14, dir, '0.14 0.08 0');
  336. };
  337.  
  338.  
  339. /*
  340. ==============================================================================
  341.  
  342. ROCKETS
  343.  
  344. ==============================================================================
  345. */
  346.  
  347. void()  s_explode1      =       [0,             s_explode2] {};
  348. void()  s_explode2      =       [1,             s_explode3] {};
  349. void()  s_explode3      =       [2,             s_explode4] {};
  350. void()  s_explode4      =       [3,             s_explode5] {};
  351. void()  s_explode5      =       [4,             s_explode6] {};
  352. void()  s_explode6      =       [5,             SUB_Remove] {};
  353.  
  354. void() BecomeExplosion =
  355. {
  356.     self.movetype = MOVETYPE_NONE;
  357.     self.velocity = '0 0 0';
  358.     self.touch = SUB_Null;
  359.     setmodel (self, "progs/s_explod.spr");
  360.     self.solid = SOLID_NOT;
  361.     s_explode1 ();
  362. };
  363.  
  364. void() T_MissileTouch =
  365. {
  366.     local float     damg;
  367.  
  368.     if (other == self.owner)
  369.         return;         // don't explode on owner
  370.  
  371.     if (pointcontents(self.origin) == CONTENT_SKY)
  372.     {
  373.         remove(self);
  374.         return;
  375.     }
  376.  
  377.     damg = 70 + random()*20;
  378.     
  379.     if (other.health)
  380.     {
  381.         if (other.classname == "monster_shambler")
  382.             damg = damg * 0.5;      // mostly immune
  383.         T_Damage (other, self, self.owner, damg );
  384.     }
  385.  
  386.     // don't do radius damage to the other, because all the damage
  387.     // was done in the impact
  388.     T_RadiusDamage (self, self.owner, 120, other);
  389.  
  390. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  391.     self.origin = self.origin - 8*normalize(self.velocity);
  392.  
  393.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  394.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  395.     WriteCoord (MSG_BROADCAST, self.origin_x);
  396.     WriteCoord (MSG_BROADCAST, self.origin_y);
  397.     WriteCoord (MSG_BROADCAST, self.origin_z);
  398.  
  399.     BecomeExplosion ();
  400. };
  401.  
  402.  
  403.  
  404. /*
  405. ================
  406. W_FireRocket
  407. ================
  408. */
  409. void() W_FireRocket =
  410. {
  411.     local   entity missile, mpuff;
  412.     
  413.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  414.     
  415.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  416.  
  417.     self.punchangle_x = -2;
  418.  
  419.     missile = spawn ();
  420.     missile.owner = self;
  421.     missile.movetype = MOVETYPE_FLYMISSILE;
  422.     missile.solid = SOLID_BBOX;
  423.         
  424. // set missile speed    
  425.  
  426.     makevectors (self.v_angle);
  427.     missile.velocity = aim(self, 1000);
  428.     missile.velocity = missile.velocity * 1000;
  429.     missile.angles = vectoangles(missile.velocity);
  430.     
  431.     missile.touch = T_MissileTouch;
  432.     
  433. // set missile duration
  434.     missile.nextthink = time + 5;
  435.     missile.think = SUB_Remove;
  436.  
  437.     setmodel (missile, "progs/missile.mdl");
  438.     setsize (missile, '0 0 0', '0 0 0');            
  439.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  440. };
  441.  
  442. /*
  443. ===============================================================================
  444.  
  445. LIGHTNING
  446.  
  447. ===============================================================================
  448. */
  449.  
  450. /*
  451. =================
  452. LightningDamage
  453. =================
  454. */
  455. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  456. {
  457.     local entity            e1, e2;
  458.     local vector            f;
  459.     
  460.     f = p2 - p1;
  461.     normalize (f);
  462.     f_x = 0 - f_y;
  463.     f_y = f_x;
  464.     f_z = 0;
  465.     f = f*16;
  466.  
  467.     e1 = e2 = world;
  468.  
  469.     traceline (p1, p2, FALSE, self);
  470.     if (trace_ent.takedamage)
  471.     {
  472.         particle (trace_endpos, '0 0 100', 225, damage*4);
  473.         T_Damage (trace_ent, from, from, damage);
  474.         if (self.classname == "player")
  475.         {
  476.             if (other.classname == "player")
  477.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  478.         }
  479.     }
  480.     e1 = trace_ent;
  481.  
  482.     traceline (p1 + f, p2 + f, FALSE, self);
  483.     if (trace_ent != e1 && trace_ent.takedamage)
  484.     {
  485.         particle (trace_endpos, '0 0 100', 225, damage*4);
  486.         T_Damage (trace_ent, from, from, damage);
  487.     }
  488.     e2 = trace_ent;
  489.  
  490.     traceline (p1 - f, p2 - f, FALSE, self);
  491.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  492.     {
  493.         particle (trace_endpos, '0 0 100', 225, damage*4);
  494.         T_Damage (trace_ent, from, from, damage);
  495.     }
  496. };
  497.  
  498.  
  499. void() W_FireLightning =
  500. {
  501.     local   vector          org;
  502.  
  503.     if (self.ammo_cells < 1)
  504.     {
  505.         self.ammo_cells = 0;
  506.         self.weapon = W_BestWeapon ();
  507.         W_SetCurrentAmmo ();
  508.         return;
  509.     }
  510.  
  511. //explode if under water
  512.     if (self.waterlevel > 1)
  513.     {
  514.         T_RadiusDamage (self, self, 860, self.enemy);
  515.         self.ammo_cells = 0;
  516.         W_SetCurrentAmmo ();
  517.         return;
  518.     }
  519.  
  520.     if (self.t_width < time)
  521.     {
  522.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  523.         self.t_width = time + 0.6;
  524.     }
  525.     self.punchangle_x = -2;
  526.  
  527.     //self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  528.  
  529.     org = self.origin + '0 0 16';
  530.     
  531.     traceline (org, org + v_forward*600, TRUE, self);
  532.  
  533.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  534.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  535.     WriteEntity (MSG_BROADCAST, self);
  536.     WriteCoord (MSG_BROADCAST, org_x);
  537.     WriteCoord (MSG_BROADCAST, org_y);
  538.     WriteCoord (MSG_BROADCAST, org_z);
  539.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  540.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  541.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  542.  
  543.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  544. };
  545.  
  546.  
  547. //=============================================================================
  548.  
  549.  
  550. void() GrenadeExplode =
  551. {
  552.     T_RadiusDamage (self, self.owner, 120, world);
  553.  
  554.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  555.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  556.     WriteCoord (MSG_BROADCAST, self.origin_x);
  557.     WriteCoord (MSG_BROADCAST, self.origin_y);
  558.     WriteCoord (MSG_BROADCAST, self.origin_z);
  559.  
  560.     BecomeExplosion ();
  561. };
  562.  
  563. void() GrenadeTouch =
  564. {
  565.     if (other == self.owner)
  566.         return;         // don't explode on owner
  567.     if (other.takedamage == DAMAGE_AIM)
  568.     {
  569.         GrenadeExplode();
  570.         return;
  571.     }
  572.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  573.     if (self.velocity == '0 0 0')
  574.         self.avelocity = '0 0 0';
  575. };
  576.  
  577. /*
  578. ================
  579. W_FireGrenade
  580. ================
  581. */
  582. void() W_FireGrenade =
  583. {
  584.     local   entity missile, mpuff;
  585.     
  586.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  587.     
  588.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  589.  
  590.     self.punchangle_x = -2;
  591.  
  592.     missile = spawn ();
  593.     missile.owner = self;
  594.     missile.movetype = MOVETYPE_BOUNCE;
  595.     missile.solid = SOLID_BBOX;
  596.     missile.classname = "grenade";
  597.         
  598. // set missile speed    
  599.  
  600.     makevectors (self.v_angle);
  601.  
  602.     if (self.v_angle_x)
  603.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  604.     else
  605.     {
  606.         missile.velocity = aim(self, 10000);
  607.         missile.velocity = missile.velocity * 600;
  608.         missile.velocity_z = 200;
  609.     }
  610.  
  611.     missile.avelocity = '300 300 300';
  612.  
  613.     missile.angles = vectoangles(missile.velocity);
  614.     
  615.     missile.touch = GrenadeTouch;
  616.     
  617. // set missile duration
  618.     missile.nextthink = time + 2.5;
  619.     missile.think = GrenadeExplode;
  620.  
  621.     setmodel (missile, "progs/grenade.mdl");
  622.     setsize (missile, '0 0 0', '0 0 0');            
  623.     setorigin (missile, self.origin);
  624. };
  625.  
  626.  
  627. //=============================================================================
  628.  
  629. void() spike_touch;
  630. void() superspike_touch;
  631.  
  632.  
  633. /*
  634. ===============
  635. launch_spike
  636.  
  637. Used for both the player and the ogre
  638. ===============
  639. */
  640. void(vector org, vector dir) launch_spike =
  641. {
  642.     newmis = spawn ();
  643.     newmis.owner = self;
  644.     newmis.movetype = MOVETYPE_FLYMISSILE;
  645.     newmis.solid = SOLID_BBOX;
  646.  
  647.     newmis.angles = vectoangles(dir);
  648.     
  649.     newmis.touch = spike_touch;
  650.     newmis.classname = "spike";
  651.     newmis.think = SUB_Remove;
  652.     newmis.nextthink = time + 6;
  653.     setmodel (newmis, "progs/spike.mdl");
  654.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  655.     setorigin (newmis, org);
  656.  
  657.     newmis.velocity = dir * 1000;
  658. };
  659.  
  660. void() W_FireSuperSpikes =
  661. {
  662.     local vector    dir;
  663.     local entity    old;
  664.     
  665.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  666.     self.attack_finished = time + 0.2;
  667.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  668.     dir = aim (self, 1000);
  669.     launch_spike (self.origin + '0 0 16', dir);
  670.     newmis.touch = superspike_touch;
  671.     setmodel (newmis, "progs/s_spike.mdl");
  672.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  673.     self.punchangle_x = -2;
  674. };
  675.  
  676. void(float ox) W_FireSpikes =
  677. {
  678.     local vector    dir;
  679.     local entity    old;
  680.     
  681.     makevectors (self.v_angle);
  682.     
  683.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  684.     {
  685.         W_FireSuperSpikes ();
  686.         return;
  687.     }
  688.  
  689.     if (self.ammo_nails < 1)
  690.     {
  691.         self.weapon = W_BestWeapon ();
  692.         W_SetCurrentAmmo ();
  693.         return;
  694.     }
  695.  
  696.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  697.     self.attack_finished = time + 0.2;
  698.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  699.     dir = aim (self, 1000);
  700.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  701.  
  702.     self.punchangle_x = -2;
  703. };
  704.  
  705.  
  706.  
  707. .float hit_z;
  708. void() spike_touch =
  709. {
  710. local float rand;
  711.     if (other == self.owner)
  712.         return;
  713.  
  714.     if (other.solid == SOLID_TRIGGER)
  715.         return; // trigger field, do nothing
  716.  
  717.     if (pointcontents(self.origin) == CONTENT_SKY)
  718.     {
  719.         remove(self);
  720.         return;
  721.     }
  722.     
  723. // hit something that bleeds
  724.     if (other.takedamage)
  725.     {
  726.         spawn_touchblood (9);
  727.         T_Damage (other, self, self.owner, 9);
  728.     }
  729.     else
  730.     {
  731.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  732.         
  733.         if (self.classname == "wizspike")
  734.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  735.         else if (self.classname == "knightspike")
  736.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  737.         else
  738.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  739.         WriteCoord (MSG_BROADCAST, self.origin_x);
  740.         WriteCoord (MSG_BROADCAST, self.origin_y);
  741.         WriteCoord (MSG_BROADCAST, self.origin_z);
  742.     }
  743.  
  744.     remove(self);
  745.  
  746. };
  747.  
  748. void() superspike_touch =
  749. {
  750. local float rand;
  751.     if (other == self.owner)
  752.         return;
  753.  
  754.     if (other.solid == SOLID_TRIGGER)
  755.         return; // trigger field, do nothing
  756.  
  757.     if (pointcontents(self.origin) == CONTENT_SKY)
  758.     {
  759.         remove(self);
  760.         return;
  761.     }
  762.     
  763. // hit something that bleeds
  764.     if (other.takedamage)
  765.     {
  766.         spawn_touchblood (18);
  767.         T_Damage (other, self, self.owner, 18);
  768.     }
  769.     else
  770.     {
  771.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  772.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  773.         WriteCoord (MSG_BROADCAST, self.origin_x);
  774.         WriteCoord (MSG_BROADCAST, self.origin_y);
  775.         WriteCoord (MSG_BROADCAST, self.origin_z);
  776.     }
  777.  
  778.     remove(self);
  779.  
  780. };
  781.  
  782.  
  783. /*
  784. ===============================================================================
  785.  
  786. PLAYER WEAPON USE
  787.  
  788. ===============================================================================
  789. */
  790.  
  791. void() W_SetCurrentAmmo =
  792. {
  793.     player_run ();          // get out of any weapon firing states
  794.  
  795.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  796.     if (self.ishead == 1)
  797.     {
  798.         self.currentammo = 0;
  799.         self.weaponmodel = "";
  800.         self.weaponframe = 0;
  801.     }
  802.     else if (self.weapon == QJ_TEETH)
  803.     {
  804.         self.currentammo = 0;
  805.         self.weaponmodel = "";
  806.         self.weaponframe = 0;
  807.     }
  808.     else if (self.weapon == IT_AXE)
  809.     {
  810.         self.currentammo = 0;
  811.         self.weaponmodel = "progs/v_axe.mdl";
  812.         self.weaponframe = 0;
  813.     }
  814.     else if (self.weapon == IT_SHOTGUN)
  815.     {
  816.         self.currentammo = self.ammo_shells;
  817.         self.weaponmodel = "progs/v_shot.mdl";
  818.         self.weaponframe = 0;
  819.         self.items = self.items | IT_SHELLS;
  820.     }
  821.     else if (self.weapon == IT_SUPER_SHOTGUN)
  822.     {
  823.         self.currentammo = self.ammo_shells;
  824.         self.weaponmodel = "progs/v_shot2.mdl";
  825.         self.weaponframe = 0;
  826.         self.items = self.items | IT_SHELLS;
  827.     }
  828.     else if (self.weapon == IT_NAILGUN)
  829.     {
  830.         self.currentammo = self.ammo_nails;
  831.         self.weaponmodel = "progs/v_nail.mdl";
  832.         self.weaponframe = 0;
  833.         self.items = self.items | IT_NAILS;
  834.     }
  835.     else if (self.weapon == IT_SUPER_NAILGUN)
  836.     {
  837.         self.currentammo = self.ammo_nails;
  838.         self.weaponmodel = "progs/v_nail2.mdl";
  839.         self.weaponframe = 0;
  840.         self.items = self.items | IT_NAILS;
  841.     }
  842.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  843.     {
  844.         self.currentammo = self.ammo_rockets;
  845.         self.weaponmodel = "progs/v_rock.mdl";
  846.         self.weaponframe = 0;
  847.         self.items = self.items | IT_ROCKETS;
  848.     }
  849.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  850.     {
  851.         self.currentammo = self.ammo_rockets;
  852.         self.weaponmodel = "progs/v_rock2.mdl";
  853.         self.weaponframe = 0;
  854.         self.items = self.items | IT_ROCKETS;
  855.     }
  856.     else if (self.weapon == IT_LIGHTNING)
  857.     {
  858.         self.currentammo = self.ammo_cells;
  859.         self.weaponmodel = "progs/v_light.mdl";
  860.         self.weaponframe = 0;
  861.         self.items = self.items | IT_CELLS;
  862.     }
  863.     else
  864.     {
  865.         self.currentammo = 0;
  866.         self.weaponmodel = "progs/v_axe.mdl";
  867.         self.weaponframe = 0;
  868.         self.weapon = IT_AXE;
  869.     }
  870. };
  871.  
  872. float() W_BestWeapon =
  873. {
  874.     local   float   it;
  875.     
  876.     it = self.items;
  877.  
  878.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  879.         return IT_LIGHTNING;
  880.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  881.         return IT_SUPER_NAILGUN;
  882.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  883.         return IT_SUPER_SHOTGUN;
  884.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  885.         return IT_NAILGUN;
  886.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  887.         return IT_SHOTGUN;
  888.         
  889. /*
  890.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  891.         return IT_ROCKET_LAUNCHER;
  892.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  893.         return IT_GRENADE_LAUNCHER;
  894.  
  895. */
  896.     if(self.ishead == 1)   //QJOE
  897.     return QJ_TEETH;  //QJOE
  898.     else
  899.     return IT_AXE;
  900. };
  901.  
  902. float() W_CheckNoAmmo =
  903. {
  904.     if (self.currentammo > 0)
  905.         return TRUE;
  906.  
  907.     if (self.weapon == IT_AXE)
  908.         return TRUE;
  909.     
  910.     if (self.weapon == QJ_TEETH)   //QJOE
  911.         return TRUE;   //QJOE
  912.  
  913.     self.weapon = W_BestWeapon ();
  914.  
  915.     W_SetCurrentAmmo ();
  916.     
  917. // drop the weapon down
  918.     return FALSE;
  919. };
  920.  
  921. /*
  922. ============
  923. W_Attack
  924.  
  925. An attack impulse can be triggered now
  926. ============
  927. */
  928. void()  player_axe1;
  929. void()  player_axeb1;
  930. void()  player_axec1;
  931. void()  player_axed1;
  932. void()  player_shot1;
  933. void()  player_nail1;
  934. void()  player_light1;
  935. void()  player_rocket1;
  936.  
  937. void() W_Attack =
  938. {
  939.     local   float   r;
  940.  
  941.     if (!W_CheckNoAmmo ())
  942.         return;
  943.  
  944.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  945.     self.show_hostile = time + 1;   // wake monsters up
  946.  
  947.     if (self.weapon == IT_AXE)
  948.     {
  949.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  950.         r = random();
  951.         if (r < 0.25)
  952.             player_axe1 ();
  953.         else if (r<0.5)
  954.             player_axeb1 ();
  955.         else if (r<0.75)
  956.             player_axec1 ();
  957.         else
  958.             player_axed1 ();
  959.         self.attack_finished = time + 0.5;
  960.     }
  961.     else if (self.weapon == IT_SHOTGUN)
  962.     {
  963.         player_shot1 ();
  964.         W_FireShotgun ();
  965.         self.attack_finished = time + 0.5;
  966.     }
  967.     else if (self.weapon == IT_SUPER_SHOTGUN)
  968.     {
  969.         player_shot1 ();
  970.         W_FireSuperShotgun ();
  971.         self.attack_finished = time + 0.7;
  972.     }
  973.     else if (self.weapon == IT_NAILGUN)
  974.     {
  975.         player_nail1 ();
  976.     }
  977.     else if (self.weapon == IT_SUPER_NAILGUN)
  978.     {
  979.         player_nail1 ();
  980.     }
  981.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  982.     {
  983.         player_rocket1();
  984.         W_FireGrenade();
  985.         self.attack_finished = time + 0.6;
  986.     }
  987.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  988.     {
  989.         player_rocket1();
  990.         W_FireRocket();
  991.         self.attack_finished = time + 0.8;
  992.     }
  993.     else if (self.weapon == IT_LIGHTNING)
  994.     {
  995.         player_light1();
  996.         self.attack_finished = time + 0.1;
  997.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  998.     }
  999.     // QJOE
  1000.     else if (self.weapon == QJ_TEETH)
  1001.     {
  1002.         W_Bite();
  1003.         sound (self, CHAN_WEAPON, "dog/idle.wav", 1, ATTN_NORM);
  1004.         self.attack_finished = time + 0.5;
  1005.     }
  1006.         
  1007. };
  1008.  
  1009. /*
  1010. ============
  1011. W_ChangeWeapon
  1012.  
  1013. ============
  1014. */
  1015. void() W_ChangeWeapon =
  1016. {
  1017.     local   float   it, am, fl;
  1018.     
  1019.     it = self.items;
  1020.     am = 0;
  1021.     //===QJOE===
  1022.     if (self.ishead == 1)
  1023.     {
  1024.     fl = QJ_TEETH;        
  1025.     sprint (self, "You can currently only use your teeth!");
  1026.     self.weapon = fl;               
  1027.     W_SetCurrentAmmo ();
  1028.     return;
  1029.     }
  1030.     if (self.impulse == 50)
  1031.     {
  1032.         self.items = self.items | QJ_TEETH;
  1033.         fl = QJ_TEETH;
  1034.     }
  1035.     //===QJOE.end===
  1036.     else if (self.impulse == 1)
  1037.     {
  1038.         fl = IT_AXE;
  1039.     }
  1040.     else if (self.impulse == 2)
  1041.     {
  1042.         fl = IT_SHOTGUN;
  1043.         if (self.ammo_shells < 1)
  1044.             am = 1;
  1045.     }
  1046.     else if (self.impulse == 3)
  1047.     {
  1048.         fl = IT_SUPER_SHOTGUN;
  1049.         if (self.ammo_shells < 2)
  1050.             am = 1;
  1051.     }               
  1052.     else if (self.impulse == 4)
  1053.     {
  1054.         fl = IT_NAILGUN;
  1055.         if (self.ammo_nails < 1)
  1056.             am = 1;
  1057.     }
  1058.     else if (self.impulse == 5)
  1059.     {
  1060.         fl = IT_SUPER_NAILGUN;
  1061.         if (self.ammo_nails < 2)
  1062.             am = 1;
  1063.     }
  1064.     else if (self.impulse == 6)
  1065.     {
  1066.         fl = IT_GRENADE_LAUNCHER;
  1067.         if (self.ammo_rockets < 1)
  1068.             am = 1;
  1069.     }
  1070.     else if (self.impulse == 7)
  1071.     {
  1072.         fl = IT_ROCKET_LAUNCHER;
  1073.         if (self.ammo_rockets < 1)
  1074.             am = 1;
  1075.     }
  1076.     else if (self.impulse == 8)
  1077.     {
  1078.         fl = IT_LIGHTNING;
  1079.         if (self.ammo_cells < 1)
  1080.             am = 1;
  1081.     }
  1082.  
  1083.     self.impulse = 0;
  1084.     
  1085.     if (!(self.items & fl))
  1086.     {       // don't have the weapon or the ammo
  1087.         sprint (self, "no weapon.\n");
  1088.         return;
  1089.     }
  1090.     
  1091.     if (am)
  1092.     {       // don't have the ammo
  1093.         sprint (self, "not enough ammo.\n");
  1094.         return;
  1095.     }
  1096.     
  1097.     self.weapon = fl;               
  1098.     W_SetCurrentAmmo ();
  1099.     
  1100. };
  1101.  
  1102. /*
  1103. ============
  1104. CheatCommand
  1105. ============
  1106. */
  1107. void() CheatCommand =
  1108. {
  1109.     if (deathmatch || coop)
  1110.         return;
  1111.     if (self.ishead == 1)
  1112.     {
  1113.         sprint (self, "Silly head, you can't cheat!");
  1114.         return;
  1115.     }
  1116.     self.ammo_rockets = 100;
  1117.     self.ammo_nails = 200;
  1118.     self.ammo_shells = 100;
  1119.     self.items = self.items | 
  1120.         IT_AXE |
  1121.         IT_SHOTGUN |
  1122.         IT_SUPER_SHOTGUN |
  1123.         IT_NAILGUN |
  1124.         IT_SUPER_NAILGUN |
  1125.         IT_GRENADE_LAUNCHER |
  1126.         IT_ROCKET_LAUNCHER |
  1127.         IT_KEY1 | IT_KEY2;
  1128.  
  1129.     self.ammo_cells = 200;
  1130.     self.items = self.items | IT_LIGHTNING;
  1131.  
  1132.     self.weapon = IT_ROCKET_LAUNCHER;
  1133.     self.impulse = 0;
  1134.     W_SetCurrentAmmo ();
  1135. };
  1136.  
  1137. /*
  1138. ============
  1139. CycleWeaponCommand
  1140.  
  1141. Go to the next weapon with ammo
  1142. ============
  1143. */
  1144. void() CycleWeaponCommand =
  1145. {
  1146.     local   float   it, am;
  1147.     
  1148.     it = self.items;
  1149.     self.impulse = 0;
  1150.     if (self.ishead == 1)
  1151.         return;
  1152.     while (1)
  1153.     {
  1154.         am = 0;
  1155.  
  1156.         if (self.weapon == IT_LIGHTNING)
  1157.         {
  1158.             self.weapon = IT_AXE;
  1159.         }
  1160.         else if (self.weapon == QJ_TEETH)
  1161.         {
  1162.             self.weapon = IT_AXE;
  1163.         }
  1164.         else if (self.weapon == IT_AXE)
  1165.         {
  1166.             self.weapon = IT_SHOTGUN;   //QJOE
  1167.             if (self.ammo_shells < 1)   //QJOE
  1168.                 am = 1;             //QJOE
  1169.         }                                   //QJOE
  1170.         else if (self.weapon == IT_SHOTGUN)
  1171.         {
  1172.             self.weapon = IT_SUPER_SHOTGUN;
  1173.             if (self.ammo_shells < 2)
  1174.                 am = 1;
  1175.         }               
  1176.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1177.         {
  1178.             self.weapon = IT_NAILGUN;
  1179.             if (self.ammo_nails < 1)
  1180.                 am = 1;
  1181.         }
  1182.         else if (self.weapon == IT_NAILGUN)
  1183.         {
  1184.             self.weapon = IT_SUPER_NAILGUN;
  1185.             if (self.ammo_nails < 2)
  1186.                 am = 1;
  1187.         }
  1188.         else if (self.weapon == IT_SUPER_NAILGUN)
  1189.         {
  1190.             self.weapon = IT_GRENADE_LAUNCHER;
  1191.             if (self.ammo_rockets < 1)
  1192.                 am = 1;
  1193.         }
  1194.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1195.         {
  1196.             self.weapon = IT_ROCKET_LAUNCHER;
  1197.             if (self.ammo_rockets < 1)
  1198.                 am = 1;
  1199.         }
  1200.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1201.         {
  1202.             self.weapon = IT_LIGHTNING;
  1203.             if (self.ammo_cells < 1)
  1204.                 am = 1;
  1205.         }
  1206.     
  1207.         if ( (self.items & self.weapon) && am == 0)
  1208.         {
  1209.             W_SetCurrentAmmo ();
  1210.             return;
  1211.         }
  1212.     }
  1213.  
  1214. };
  1215.  
  1216. /*
  1217. ============
  1218. ServerflagsCommand
  1219.  
  1220. Just for development
  1221. ============
  1222. */
  1223. void() ServerflagsCommand =
  1224. {
  1225.     serverflags = serverflags * 2 + 1;
  1226. };
  1227.  
  1228. void() QuadCheat =
  1229. {
  1230.     if (deathmatch || coop)
  1231.         return;
  1232.     if (self.ishead == 1)
  1233.         return;
  1234.     self.super_time = 1;
  1235.     self.super_damage_finished = time + 30;
  1236.     self.items = self.items | IT_QUAD;
  1237.     dprint ("quad cheat\n");
  1238. };
  1239.  
  1240. /*
  1241. ============
  1242. ImpulseCommands
  1243.  
  1244. ============
  1245. */
  1246. void() ImpulseCommands =
  1247. {
  1248.     if (self.impulse >= 1 && self.impulse <= 8)
  1249.         W_ChangeWeapon ();
  1250.     if (self.impulse == 50)
  1251.     {
  1252.         W_ChangeWeapon ();
  1253.     }
  1254.     if (self.impulse == 9)
  1255.         CheatCommand ();
  1256.     if (self.impulse == 10)
  1257.         CycleWeaponCommand ();
  1258.     if (self.impulse == 11)
  1259.         ServerflagsCommand ();
  1260.  
  1261.     if (self.impulse == 255)
  1262.         QuadCheat ();
  1263.         
  1264.     self.impulse = 0;
  1265. };
  1266.  
  1267. /*
  1268. ============
  1269. W_WeaponFrame
  1270.  
  1271. Called every frame so impulse events can be handled as well as possible
  1272. ============
  1273. */
  1274. void() W_WeaponFrame =
  1275. {
  1276.     if (time < self.attack_finished)
  1277.         return;
  1278.  
  1279.     ImpulseCommands ();
  1280.     
  1281. // check for attack
  1282.     if (self.button0)
  1283.     {
  1284.         SuperDamageSound ();
  1285.         W_Attack ();
  1286.     }
  1287. };
  1288.  
  1289. /*
  1290. ========
  1291. SuperDamageSound
  1292.  
  1293. Plays sound if needed
  1294. ========
  1295. */
  1296. void() SuperDamageSound =
  1297. {
  1298.     if (self.super_damage_finished > time)
  1299.     {
  1300.         if (self.super_sound < time)
  1301.         {
  1302.             self.super_sound = time + 1;
  1303.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1304.         }
  1305.     }
  1306.     return;
  1307. };
  1308.  
  1309.  
  1310.